package com.yytek.pm.tddb.mqtt;

import com.yytek.common.client.base.MqMessage;
import com.yytek.common.client.net.IotMqttClient;
import com.yytek.common.client.net.IotMqttContext;
import com.yytek.common.client.net.MqttCallback;
import com.yytek.common.core.constant.CacheConstants;
import com.yytek.common.core.constant.MqttConstants;
import com.yytek.common.redis.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.ThreadPoolExecutor;

@Service
@Slf4j
public class TddbMqttService implements MqttCallback {

    @Resource
    IotMqttClient iotMqttClient;
    @Resource
    private ThreadPoolExecutor threadPoolExecutor;
    @Resource
    private RedisService redisService;

    @PostConstruct
    public void init() {
        //订阅tddb业务
        iotMqttClient.subscribe(MqttConstants.PM_TDDB_TOPIC,this);
    }
    @Override
    public void onMessageReceived(IotMqttContext context, MqMessage msg) {
        //业务处理
        System.out.println("---topic----"+context.getTopic());
//        System.out.println("---getProductId----"+context.getProductId());
//        System.out.println("---getDeviceName----"+context.getDeviceName());
//        System.out.println("---msgid----"+msg.getMessageId());
//        System.out.println("---msg----"+msg.getJsonObject().toJSONString());
        //收取到时序数据库业务后 多线程 放入redis队列中
        redisService.setCacheQueue(CacheConstants.TDDB_INSERT_QUEUE_KEY,msg);
    }


}
